`
https://leetcode.cn/problems/best-time-to-buy-and-sell-stock-iii/
`

/**
 * @param {number[]} prices
 * @return {number}
 */
var maxProfit = function (prices) {
  const max_k = 2, n = prices.length;
  const dp = new Array(n).fill().map(() => new Array(max_k + 1).fill().map(() => new Array(2).fill(0)));
  for (let i = 0; i < n; i++) {
    for (let k = max_k; k >= 1; k--) {
      if (i - 1 == -1) {
        // 处理 base case
        dp[i][k][0] = 0;
        dp[i][k][1] = -prices[i];
        continue;
      }
      dp[i][k][0] = Math.max(dp[i - 1][k][0], dp[i - 1][k][1] + prices[i]);
      dp[i][k][1] = Math.max(dp[i - 1][k][1], dp[i - 1][k - 1][0] - prices[i]);
    }
  }
  // 穷举了 n × max_k × 2 个状态，正确。
  return dp[n - 1][max_k][0];
};